package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.SetMeal;
import com.fantastic.service.zjs.SetMealService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/1 15:50
 * @description: 套餐信息表控制器
 */
@RestController
@RequestMapping("/meal")
public class SetMealControllerAdmin {

    @Resource
    private SetMealService mealService;

    /**
     * 查询套餐信息
     *
     * @param setMeal
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("/listMeal")
    public ResultData listMeal(SetMeal setMeal,
                               @RequestParam(name="page",
                                       defaultValue = "1") int pageNum,
                               @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SetMeal> meals = mealService.listMeal(setMeal);
        PageInfo<SetMeal> pageInfo = new PageInfo<>(meals);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询单个套餐信息
     *
     * @param mealId 套餐信息id
     * @return
     */
    @GetMapping("/getMeal")
    public ResultData getMeal(Integer mealId) {
        return new ResultData(RespStatusInfo.OK, mealService.getMeal(mealId));
    }

    /**
     * 添加套餐信息
     *
     * @param meal 套餐信息对象
     * @return
     */
    @PostMapping("/insertMeal")
    public ResultData insertMeal(MultipartFile mealFile, SetMeal meal) {
        return new ResultData(RespStatusInfo.OK, mealService.insertMeal(mealFile, meal));
    }

    /**
     * 修改套餐信息
     *
     * @param meal
     * @return
     */
    @PostMapping("/updateMeal")
    public ResultData updateMeal(MultipartFile mealFile, SetMeal meal) {
        System.out.println(mealFile);
        return new ResultData(RespStatusInfo.OK, mealService.updateMeal(mealFile, meal));
    }

    /**
     * 删除套餐信息
     *
     * @param mealId
     * @return
     */
    @PostMapping("/deleteMeal")
    public ResultData deleteMeal(Integer mealId) {
        return new ResultData(RespStatusInfo.OK, mealService.deleteMeal(mealId));
    }

}
